/*
 * Copyright (c) 2025 CAX Conversion Project
 */
package com.comac.ins.isfd.controller;

import java.util.List;

import com.comac.ins.common.core.domain.R;
import com.comac.ins.common.core.validate.AddGroup;
import com.comac.ins.common.core.validate.EditGroup;
import com.comac.ins.common.excel.utils.ExcelUtil;
import com.comac.ins.common.idempotent.annotation.RepeatSubmit;
import com.comac.ins.common.log.annotation.Log;
import com.comac.ins.common.log.enums.BusinessType;
import com.comac.ins.common.mybatis.core.page.PageQuery;
import com.comac.ins.common.mybatis.core.page.TableDataInfo;
import com.comac.ins.common.web.core.BaseController;
import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;

import com.comac.ins.isfd.domain.vo.IsfdBusinessScenariosVo;
import com.comac.ins.isfd.domain.bo.IsfdBusinessScenariosBo;
import com.comac.ins.isfd.service.IIsfdBusinessScenariosService;

/**
 * 用于存储业务场景及其相关信息的格
 *
 * @author Lion Li
 * @date 2024-12-04
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/isfd/businessScenarios")
public class IsfdBusinessScenariosController extends BaseController {

    private final IIsfdBusinessScenariosService isfdBusinessScenariosService;

    /**
     * 查询用于存储业务场景及其相关信息的格列表
     */
    @SaCheckPermission("isfd:businessScenarios:list")
    @GetMapping("/list")
    public TableDataInfo<IsfdBusinessScenariosVo> list(IsfdBusinessScenariosBo bo, PageQuery pageQuery) {
        return isfdBusinessScenariosService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出用于存储业务场景及其相关信息的格列表
     */
    @SaCheckPermission("isfd:businessScenarios:export")
    @Log(title = "用于存储业务场景及其相关信息的格", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(IsfdBusinessScenariosBo bo, HttpServletResponse response) {
        List<IsfdBusinessScenariosVo> list = isfdBusinessScenariosService.queryList(bo);
        ExcelUtil.exportExcel(list, "用于存储业务场景及其相关信息的格", IsfdBusinessScenariosVo.class, response);
    }

    /**
     * 获取用于存储业务场景及其相关信息的格详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("isfd:businessScenarios:query")
    @GetMapping("/{id}")
    public R<IsfdBusinessScenariosVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(isfdBusinessScenariosService.queryById(id));
    }

    /**
     * 新增用于存储业务场景及其相关信息的格
     */
    @SaCheckPermission("isfd:businessScenarios:add")
    @Log(title = "用于存储业务场景及其相关信息的格", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody IsfdBusinessScenariosBo bo) {
        return toAjax(isfdBusinessScenariosService.insertByBo(bo));
    }

    /**
     * 修改用于存储业务场景及其相关信息的格
     */
    @SaCheckPermission("isfd:businessScenarios:edit")
    @Log(title = "用于存储业务场景及其相关信息的格", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody IsfdBusinessScenariosBo bo) {
        return toAjax(isfdBusinessScenariosService.updateByBo(bo));
    }

    /**
     * 删除用于存储业务场景及其相关信息的格
     *
     * @param ids 主键串
     */
    @SaCheckPermission("isfd:businessScenarios:remove")
    @Log(title = "用于存储业务场景及其相关信息的格", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(isfdBusinessScenariosService.deleteWithValidByIds(List.of(ids), true));
    }
}
